﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebSite.App_Code;
using WebSite.App_Data;
using WebSite.Models;
using System.Resources;
using System.IO;
using Excel = Microsoft.Office.Interop.Excel;
using System.Web.Configuration;
using System.Web.Security;

namespace WebSite.Controllers
{
    public class MasterDataController : BaseController
    {
        #region Action.Department

        public ActionResult Department()
        {
            return Department_Load(new DepartmentModel());
        }

        public ActionResult Department_Load(DepartmentModel ModelData)
        {
            ModelData.Init();
            ModelData.U = this.CurrentUser;
            return View("Department", ModelData);
        } 

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Department_Query(FormCollection collection)
        {
            return Department_Load(new DepartmentModel() { IsAll = (collection["IsAll"].ToUpper() == "TRUE") });
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Department_Upadte(FormCollection collection, Boolean ShowAll)
        {
            md_Department oUpdate = new md_Department()
            {
                Guid = collection["UD_ID"],
                DepartmentName = collection["UD_Name"]
            };

            DepartmentModel M = new DepartmentModel();
            M.U = this.CurrentUser;

            ViewData["DB.Operation.Result"] = M.UpdateItem(oUpdate);

            ViewData["Select"] = collection["UD_ID"];
            
            M.IsAll = ShowAll;
            return Department_Load(M);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Department_Insert(FormCollection collection, Boolean ShowAll)
        {
            String NewID = Guid.NewGuid().ToString();

            DepartmentModel M = new DepartmentModel();
            M.U = this.CurrentUser;

            ViewData["DB.Operation.Result"] = M.InsertItem(
                new md_Department
                {
                    Guid = NewID,
                    DepartmentName = collection["ID_Name"],
                    //DepartmentLevel = collection["Lv"],
                    //ParentGuid = collection["ParentID"]
                });

            ViewData["Select"] = NewID;

            M.IsAll = ShowAll;
            return Department_Load(M);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Department_Disable(FormCollection collection, Boolean ShowAll)
        {
            DepartmentModel M = new DepartmentModel();
            M.U = this.CurrentUser;

            ViewData["DB.Operation.Result"] = M.DisableItem(new md_Department { Guid = collection["DD_ID"] });

            ViewData["Select"] = collection["DD_ID"];

            M.IsAll = ShowAll;
            return Department_Load(M);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Department_Enable(FormCollection collection, Boolean ShowAll)
        {
            DepartmentModel M = new DepartmentModel();
            M.U = this.CurrentUser;

            ViewData["DB.Operation.Result"] = M.EnableItem(new md_Department { Guid = collection["ED_ID"] });

            ViewData["Select"] = collection["ED_ID"];

            M.IsAll = ShowAll;
            return Department_Load(M);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Department_Up(FormCollection collection, Boolean ShowAll)
        {
            DepartmentModel M = new DepartmentModel();
            M.U = this.CurrentUser;

            DBOperationResult result = M.UpItem(new md_Department { Guid = collection["Up_D_ID"] }, ShowAll);

            ViewData["Select"] = collection["Up_D_ID"];

            M.IsAll = ShowAll;
            return Department_Load(M);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Department_Dw(FormCollection collection, Boolean ShowAll)
        {
            DepartmentModel M = new DepartmentModel();
            M.U = this.CurrentUser;

            DBOperationResult result = M.DwItem(new md_Department { Guid = collection["Dw_D_ID"] }, ShowAll);

            ViewData["Select"] = collection["Dw_D_ID"];

            M.IsAll = ShowAll;
            return Department_Load(M);
        }

        #endregion

        #region Action.User

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult WebUser(FormCollection collection, UserModel M)
        {
            switch (M.PostingEvent)
            {
                case L_PageEvent.MD_User_Query:
                    break;
                case L_PageEvent.MD_User_Upadte:
                    WebUser_Upadte(collection, M);
                    break;
                case L_PageEvent.MD_User_Insert:
                    WebUser_Insert(collection, M);
                    break;
                case L_PageEvent.MD_User_Delete:
                    WebUser_Delete(collection, M);
                    break;
                case L_PageEvent.MD_User_Enable:
                    WebUser_Enable(collection, M);
                    break;
                case L_PageEvent.MD_User_ChangePwd:
                    WebUser_ChangePwd(collection, M);
                    break;
                case L_PageEvent.MD_User_UpdateRole:
                    WebUser_UpdateRole(collection, M);
                    break;
                case L_PageEvent.MD_User_ResetPwd:
                    WebUser_ResetPwd(collection, M);
                    break;
            }

            return WebUser(M);
        }

        public ActionResult WebUser(UserModel Model)
        {
            Model.U = this.CurrentUser;

            Model.Init();

            return View("WebUser", Model);
        }

        public void WebUser_Delete(FormCollection collection, UserModel M)
        {
            M.U = this.CurrentUser;

            ViewData["DB.Operation.Result"] = M.DeleteItem(collection["UserID_" + M.PostingID]);
        }

        public void WebUser_Upadte(FormCollection collection, UserModel M)
        {
            M.U = this.CurrentUser;

            md_User oUpdate = new md_User()
            {
                Guid = collection["UserID_" + M.PostingID],
                UserName = collection["U_Name_" + M.PostingID],
                DepartmentGuid = collection["U_Department_" + M.PostingID],
                DisplayName = collection["U_Display_" + M.PostingID],
            };

            DBOperationResult result = M.UpdateItem(oUpdate);

            ViewData["DB.Operation.Result"] = HttpContext.GetGlobalResourceObject("Message", "DBOperationResult" + Math.Abs((int)result));
        }

        public void WebUser_Insert(FormCollection collection, UserModel M)
        {
            M.U = this.CurrentUser;

            ViewData["DB.Operation.Result"] = M.InsertItem(
                 new md_User
                 {
                     UserName = collection["I_Name"].Trim(),
                     DepartmentGuid = collection["I_Department"],
                     DisplayName = collection["I_Display"].Trim(),
                     Password = FormsAuthentication.HashPasswordForStoringInConfigFile("123456", "MD5"),
                 });
        }

        public void WebUser_Enable(FormCollection collection, UserModel M)
        {
            M.U = this.CurrentUser;

            ViewData["DB.Operation.Result"] = M.EnableItem(collection["UserID_" + M.PostingID]);
        }

        public void WebUser_ChangePwd(FormCollection collection, UserModel M)
        {
            String PwdOld = collection["CP_Pwd_Old"];
            String PwdNew = collection["CP_Pwd_New"];
            String PwdConfirm = collection["CP_Pwd_Confirm"];
            String UserID = collection["CP_UserID"];

            M.U = this.CurrentUser;

            if (PwdNew.Trim() != PwdConfirm.Trim())
            {
                ViewData["DB.Operation.Result"] = "密码与确认密码不一致";
                return;
            }

            ViewData["DB.Operation.Result"] = M.ChangePwd(UserID,
                FormsAuthentication.HashPasswordForStoringInConfigFile(PwdOld, "MD5"),
                FormsAuthentication.HashPasswordForStoringInConfigFile(PwdNew, "MD5"));
        }

        public void WebUser_UpdateRole(FormCollection collection, UserModel M)
        {
            M.U = this.CurrentUser;

            List<SelectListItem> ListRole = new List<SelectListItem>();

            foreach (String Role in collection["UR_UpdateRole"].Split(','))
            {
                if (!String.IsNullOrEmpty(Role))
                    ListRole.Add(new SelectListItem() { Value = Role });
            }

            RoleRelationItem Update = new RoleRelationItem()
            {
                User = new UserItem()
                {
                    User = new md_User()
                    {
                        Guid = collection["UR_UpdateUser"]
                    }
                },
                RoleList = ListRole
            };

            RoleRelationModel.UpdateItem(Update);

            ViewData["DB.Operation.Result"] = HttpContext.GetGlobalResourceObject("Message", "DBOperationResult" + Math.Abs((int)(DBOperationResult.Update_Success)));
        }

        public void WebUser_ResetPwd(FormCollection collection, UserModel M)
        {
            M.U = this.CurrentUser;
            
            ViewData["DB.Operation.Result"] = M.ResetPwd(collection["UserID_" + M.PostingID],
                FormsAuthentication.HashPasswordForStoringInConfigFile("123456", "MD5"));
        }


        #endregion

        #region Action.ExpenseCategory

        public ActionResult ExpenseCategory()
        {
            return ExpenseCategory_Load(new ExpenseCategoryModel());
        }

        public ActionResult ExpenseCategory_Load(ExpenseCategoryModel ModelData)
        {
            ModelData.Init();
            ModelData.U = this.CurrentUser;
            return View("ExpenseCategory", ModelData);
        } 

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ExpenseCategory_Upadte(FormCollection collection, Boolean ShowAll)
        {
            md_ExpenseCategory oUpdate = new md_ExpenseCategory()
            {
                Guid = collection["U_ID"],
                CategoryName = collection["U_Name"],
                CategoryGroup = collection["U_Group"],
                ParentGuid = collection["U_PID"],
                HasChid = (collection["I_HasC"] != null),
            };

            ExpenseCategoryModel M = new ExpenseCategoryModel();
            M.U = this.CurrentUser;

            ViewData["DB.Operation.Result"] = M.UpdateItem(oUpdate);

            M.IsAll = ShowAll;
            return ExpenseCategory_Load(M);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ExpenseCategory_Insert(FormCollection collection, Boolean ShowAll)
        {
            ExpenseCategoryModel M = new ExpenseCategoryModel();
            M.U = this.CurrentUser;

            ViewData["DB.Operation.Result"] = M.InsertItem(
                new md_ExpenseCategory
                {
                    CategoryName = collection["I_Name"],
                    CategoryGroup = collection["I_Group"],
                    ParentGuid = collection["I_PID"],
                    HasChid = (collection["I_HasC"] != null),
                });

            M.IsAll = ShowAll;
            return ExpenseCategory_Load(M);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ExpenseCategory_Disable(FormCollection collection, Boolean ShowAll)
        {
            ExpenseCategoryModel M = new ExpenseCategoryModel();
            M.U = this.CurrentUser;

            ViewData["DB.Operation.Result"] = M.DisableItem(new md_ExpenseCategory() { Guid = collection["ID"] });

            M.IsAll = ShowAll;
            return ExpenseCategory_Load(M);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ExpenseCategory_Enable(FormCollection collection, Boolean ShowAll)
        {
            ExpenseCategoryModel M = new ExpenseCategoryModel();
            M.U = this.CurrentUser;

            ViewData["DB.Operation.Result"] = M.EnableItem(new md_ExpenseCategory() { Guid = collection["ID"] });

            M.IsAll = ShowAll;
            return ExpenseCategory_Load(M);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult ExpenseCategory_Query(FormCollection collection)
        {
            return ExpenseCategory_Load(new ExpenseCategoryModel() { IsAll = (collection["IsAll"].ToUpper() == "TRUE") });
        }

        public ActionResult ExpenseCategory_GetParent(string Group)
        {
            return Json(ExpenseCategoryModel.GetParent(Group), JsonRequestBehavior.AllowGet);
        }

        #endregion

        #region Action.Role

        public ActionResult Role(RoleModel ModelData)
        {
            ModelData.Insert = RoleModel.GetInsert();
            ModelData.GetTable();

            return View("Role", ModelData);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Role_Insert(FormCollection collection)
        {

            RoleItem Insert = new RoleItem();

            string[] arryItem = collection["OrderID"].Split(',');
            string[] arryDepartment = collection["Department"].Split(',');
            string[] arryProjectCtegory = collection["ProjectCtegory"].Split(',');

            Insert.Role.RoleName = collection["RoleName"];
            Insert.Role.RoleDescription = collection["RoleDescription"];
            Insert.PageList = collection["IR_PageString"].Split(';').ToList();

            for (int i = 0; i < arryItem.Length; i++)
            {
                SubRoleItem One = new SubRoleItem()
                {
                    OpenAuth = new SubRole_Open(CommonItem.X_Sum(collection["OpenAuth"].Split(',').Skip(i * 4).Take(4).ToList()).ToString()),
                    UploadAuth = new SubRole_Upload(CommonItem.X_Sum(collection["UploadAuth"].Split(',').Skip(i * 5).Take(5).ToList()).ToString()),
                    AuditAuth = new SubRole_Approve(CommonItem.X_Sum(collection["AuditAuth"].Split(',').Skip(i * 4).Take(4).ToList()).ToString()),
                    InUseAuth = new SubRole_Use(CommonItem.X_Sum(collection["InUseAuth"].Split(',').Skip(i * 4).Take(4).ToList()).ToString()),
                    AdjustAuth = new SubRole_Adjust(CommonItem.X_Sum(collection["AdjustAuth"].Split(',').Skip(i * 5).Take(5).ToList()).ToString()),
                    CompleteAuth = new SubRole_Complete(CommonItem.X_Sum(collection["CompleteAuth"].Split(',').Skip(i * 2).Take(2).ToList()).ToString()),
                    CloseAuth = new SubRole_Close(CommonItem.X_Sum(collection["CloseAuth"].Split(',').Skip(i * 2).Take(2).ToList()).ToString()),
                    HistoryAuth = new SubRole_History(CommonItem.X_Sum(collection["HistoryAuth"].Split(',').Skip(i * 1).Take(1).ToList()).ToString()),
                    ProjectCtegory = new list_ProjectCategory()
                    {
                        ID = arryProjectCtegory[i]
                    }
                };

                switch (CommonItem.X_Int32(arryDepartment[i]))
                {
                    case (int)L_SubRoleType.AllDepartment:
                        One.Type = L_SubRoleType.AllDepartment;
                        break;
                    case (int)L_SubRoleType.Self:
                        One.Type = L_SubRoleType.Self;
                        break;
                    case (int)L_SubRoleType.SelfDepartment:
                       One.Type = L_SubRoleType.SelfDepartment;
                        break;
                    default:
                        One.Type = L_SubRoleType.Department;
                        One.Department.Guid = arryDepartment[i];
                        break;
                }

                Insert.RoleList.Add(One);
            }

            RoleModel.InsertItem(Insert);

            return Role(new RoleModel());
        }

        public ActionResult Role_Edit(String ID)
        {
            RoleModel Model = new RoleModel();

            Model.GetDetail(ID);

            return Role(Model);
        }

        public ActionResult Role_Update(FormCollection collection)
        {
            if (collection["OrderID"] == null || collection["Department"] == null || collection["ProjectCtegory"] == null)
                return Role(new RoleModel());

            RoleItem Update = new RoleItem();

            string[] arryItem = collection["OrderID"].Split(',');
            string[] arryDepartment = collection["Department"].Split(',');
            string[] arryProjectCtegory = collection["ProjectCtegory"].Split(',');

            Update.Role.RoleName = collection["RoleName"];
            Update.Role.RoleDescription = collection["RoleDescription"];
            Update.Role.Guid = collection["ID"];
            Update.PageList = collection["UR_PageString"].Split(';').Distinct().ToList();

            for (int i = 0; i < arryItem.Length; i++)
            {
                SubRoleItem One = new SubRoleItem()
                {
                    OpenAuth = new SubRole_Open(CommonItem.X_Sum(collection["OpenAuth"].Split(',').Skip(i * 4).Take(4).ToList()).ToString()),
                    UploadAuth = new SubRole_Upload(CommonItem.X_Sum(collection["UploadAuth"].Split(',').Skip(i * 5).Take(5).ToList()).ToString()),
                    AuditAuth = new SubRole_Approve(CommonItem.X_Sum(collection["AuditAuth"].Split(',').Skip(i * 4).Take(4).ToList()).ToString()),
                    InUseAuth = new SubRole_Use(CommonItem.X_Sum(collection["InUseAuth"].Split(',').Skip(i * 4).Take(4).ToList()).ToString()),
                    AdjustAuth = new SubRole_Adjust(CommonItem.X_Sum(collection["AdjustAuth"].Split(',').Skip(i * 5).Take(5).ToList()).ToString()),
                    CompleteAuth = new SubRole_Complete(CommonItem.X_Sum(collection["CompleteAuth"].Split(',').Skip(i * 2).Take(2).ToList()).ToString()),
                    CloseAuth = new SubRole_Close(CommonItem.X_Sum(collection["CloseAuth"].Split(',').Skip(i * 2).Take(2).ToList()).ToString()),
                    HistoryAuth = new SubRole_History(CommonItem.X_Sum(collection["HistoryAuth"].Split(',').Skip(i * 1).Take(1).ToList()).ToString()),
                    ProjectCtegory = new list_ProjectCategory()
                    {
                        ID = arryProjectCtegory[i]
                    }
                };

                switch (CommonItem.X_Int32(arryDepartment[i]))
                {
                    case (int)L_SubRoleType.AllDepartment:
                        One.Type = L_SubRoleType.AllDepartment;
                        break;
                    case (int)L_SubRoleType.Self:
                        One.Type = L_SubRoleType.Self;
                        break;
                    case (int)L_SubRoleType.SelfDepartment:
                        One.Type = L_SubRoleType.SelfDepartment;
                        break;
                    default:
                        One.Type = L_SubRoleType.Department;
                        One.Department.Guid = arryDepartment[i];
                        break;
                }

                Update.RoleList.Add(One);
            }

            RoleModel.UpdateItem(Update);

            return Role(new RoleModel());
        }

        public ActionResult Role_Delete(String ID)
        {
            RoleModel.DeleteItem(ID);

            return Role(new RoleModel());
        }

        #endregion

        #region Action.Authority

        [AcceptVerbs(HttpVerbs.Get)]
        public ActionResult RoleRelation()
        {
            RoleRelationModel ModelData = new RoleRelationModel();

            ModelData.Table = RoleRelationModel.GetTable();
            ModelData.RoleSource = RoleRelationModel.GetRoleSource();

            return View("RoleRelation", ModelData);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult RR_Update(FormCollection collection)
        {
            List<SelectListItem> ListRole = new List<SelectListItem>();

            foreach(String Role in collection["UpdateRole"].Split(','))
            {
                if (!String.IsNullOrEmpty(Role))
                    ListRole.Add(new SelectListItem() { Value = Role });
            }

            RoleRelationItem Update = new RoleRelationItem()
            {
                User = new UserItem()
                {
                    User = new md_User()
                    {
                        Guid = collection["UpdateUser"]
                    }
                },
                RoleList = ListRole
            };

            RoleRelationModel.UpdateItem(Update);

            return RoleRelation();
        }

        #endregion

        #region Action.Project

        public ActionResult Project(ProjectModel M)
        {
            M.Init();
            M.U = this.CurrentUser;
            M.Query();

            return View(M);
        }

        [AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Project(ProjectModel M, FormCollection collection)
        {
            try
            {
                switch (M.PostingEvent)
                {
                    case L_PageEvent.MD_Project_Query:
                        break;
                    case L_PageEvent.MD_Project_Delete:
                        M.DeleteItem(collection["DeleteID"].Trim());
                        ViewData["DB.Operation.Result"] = "删除成功!";
                        break;
                }
            }
            catch (Exception ex)
            {
                ViewData["DB.Operation.Result"] = ex.Message;
            }

            M.Init();
            M.U = this.CurrentUser;
            M.Query();

            return View(M);
        }

        //[AcceptVerbs(HttpVerbs.Post)]
        //public ActionResult Project_Query(FormCollection collection)
        //{
        //    return Project_Load(new ProjectModel() {
        //        Q_Department = collection["Q_Department"].Trim(),
        //        Q_PIC = collection["Q_PIC"].Trim(),
        //        Q_PjCategory = collection["Q_PjCategory"].Trim(),
        //        Q_PjCode = collection["Q_PjCode"].Trim(),
        //        Q_PjName = collection["Q_PjName"].Trim(),
        //        Q_PjType = collection["Q_PjType"].Trim(),
        //        Q_ShowAll = String.IsNullOrEmpty(collection["Q_ShowAll"]),
        //    });
        //}

        //[AcceptVerbs(HttpVerbs.Post)]
        //public ActionResult Project_Upload(FormCollection collection)
        //{
        //    if (Request.Files.Count == 0)
        //    {
        //        ViewData["DB.Operation.Result"] = "No Data";
        //        return Project();
        //    }

        //    var c = Request.Files[0];
        //    if (c == null || c.ContentLength == 0)
        //    {
        //        ViewData["DB.Operation.Result"] = "No Data";
        //        return Project();
        //    }

        //    string fileName = Guid.NewGuid().ToString().Replace("-", "") + ".xls";
        //    fileName = Server.MapPath(WebConfigurationManager.AppSettings["UploadTmpPath"]) + fileName;
        //    c.SaveAs(fileName);

        //    Excel._Application app = null;
        //    Excel.Workbook book = null;
        //    Excel.Worksheet ws = null;

        //    try
        //    {
        //        app = new Excel.ApplicationClass();

        //        book = app.Workbooks.Open(fileName, Type.Missing, Type.Missing, Type.Missing, Type.Missing
        //        , Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing
        //        , Type.Missing, Type.Missing, Type.Missing, Type.Missing);

        //        ws = (Excel.Worksheet)book.Worksheets.get_Item(1);

        //        Dictionary<String, String> lsPC = new Dictionary<String, String>();
        //        Dictionary<String, String> lsPT = new Dictionary<String, String>();
        //        Dictionary<String, String> lsBS = new Dictionary<String, String>();
        //        Dictionary<String, String> lsYN = new Dictionary<String, String>();
        //        Dictionary<String, String> lsD = new Dictionary<String, String>();
        //        Dictionary<String, String> lsAP = new Dictionary<String, String>();
        //        Dictionary<String, String> lsU = new Dictionary<String, String>();
        //        Dictionary<String, String> lsY = new Dictionary<String, String>();

        //        ExcelSheetItem.GetList(ref lsPC, ref lsPT, ref lsBS, ref lsYN, ref lsD, ref lsAP, ref lsU, ref lsY);

        //        List<List<ExcelSheetCellItem>> Table = new List<List<ExcelSheetCellItem>>();

        //        if (app.WorksheetFunction.CountA(ws.UsedRange.get_Range("B3:B" + ws.UsedRange.Rows.Count.ToString()),
        //            ws.UsedRange.get_Range("G3:G" + ws.UsedRange.Rows.Count.ToString()),
        //            ws.UsedRange.get_Range("L3:AG" + ws.UsedRange.Rows.Count.ToString())) == 0)
        //        {
        //            for (int i = 3; i <= ws.UsedRange.Rows.Count; i++)
        //            {
        //                if (app.WorksheetFunction.CountA(
        //                    ws.UsedRange.get_Range("A" + i.ToString()),
        //                    ws.UsedRange.get_Range("C" + i.ToString() + ":F" + i.ToString()),
        //                    ws.UsedRange.get_Range("H" + i.ToString() + ":K" + i.ToString())) == 0)
        //                    continue;

        //                List<ExcelSheetCellItem> Row = new List<ExcelSheetCellItem>();

        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("A" + i.ToString()).Value), IsRequired = true, IsList = true, InList = lsPC });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("B" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("C" + i.ToString()).Value) });
        //                if (Row[0].Text == lsPC["4"]) {
        //                    Row[2].IsRequired = true;
        //                    Row[2].IsList = true;
        //                    Row[2].InList = lsPT;
        //                }
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("D" + i.ToString()).Value), IsRequired = true, IsList = true, InList = lsD });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("E" + i.ToString()).Value), IsRequired = true, MaxLength = 50 });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("F" + i.ToString()).Value), IsRequired = true, MaxLength = 10 });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("G" + i.ToString()).Value) });
        //                //Row.Add(new ExcelSheetCellItem() { Value = Convert.ToString(ws.UsedRange.get_Range("G" + i.ToString()).Value), IsRequired = true, IsList = true, InList = lsAP });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("H" + i.ToString()).Value), IsRequired = true, MaxLength = 20 });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("I" + i.ToString()).Value), IsRequired = true, IsDate = true });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("J" + i.ToString()).Value), IsRequired = true, IsDate = true });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("K" + i.ToString()).Value), IsRequired = true, IsList = true, InList = lsU });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("L" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("M" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("N" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("O" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("P" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("Q" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("R" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("S" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("T" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("U" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("V" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("W" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("X" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("Y" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("Z" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("AA" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("AB" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("AC" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("AD" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("AE" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("AF" + i.ToString()).Value) });
        //                Row.Add(new ExcelSheetCellItem() { Text = Convert.ToString(ws.UsedRange.get_Range("AG" + i.ToString()).Value) });

        //                Table.Add(Row);
        //            }
        //        }

        //        if (Table.Count == 0)
        //        {
        //            ViewData["DB.Operation.Result"] = "No Data";
        //        }
        //        else
        //        {
        //            Boolean blR = ExcelSheetItem.Check(Table);

        //            ViewData["DB.Upload.Result"] = blR;

        //            ViewData["DB.Upload.Review"] = Table;
        //        }


                
        //    }
        //    catch (Exception ex)
        //    {
        //        throw ex;
        //    }
        //    finally
        //    {
        //        if (book != null)
        //            book.Close(false, Type.Missing, Type.Missing);

        //        if (app != null)
        //            app.Quit();

        //        ws = null;
        //        book = null;
        //        app = null;

        //        GC.Collect();

        //        System.IO.File.Delete(fileName);
        //    }

        //    return Project();
        //}

        //public ActionResult Project_Delete(FormCollection collection, String Q1, String Q2, String Q3, String Q4, String Q5, String Q6, Boolean Q7)
        //{
        //    ProjectModel M = new ProjectModel();
        //    M.U = this.CurrentUser;

        //    M.DeleteItem(collection["DeleteID"].Trim());

        //    return Project_Load(new ProjectModel()
        //    {
        //        Q_PjCategory = Q1,
        //        Q_PjType = Q2,
        //        Q_Department = Q3,
        //        Q_PIC = Q4,
        //        Q_PjName = Q5,
        //        Q_PjCode = Q6,
        //        Q_ShowAll = Q7,
        //    });
        //}

        #endregion
    }
}
